#include "service/AlarmManager.h"
#include "core/Logger.h"

#include <chrono>
#include <thread>

namespace ems {
namespace service {

AlarmManager::AlarmManager() : running_(false) {
}

AlarmManager::~AlarmManager() {
    stop();
}

bool AlarmManager::initialize() {
    LOG_INFO("Initializing alarm manager");
    return true;
}

void AlarmManager::start() {
    if (running_) {
        return;
    }
    
    LOG_INFO("Starting alarm manager");
    running_ = true;
    alarmThread_ = std::thread(&AlarmManager::alarmLoop, this);
}

void AlarmManager::stop() {
    if (!running_) {
        return;
    }
    
    LOG_INFO("Stopping alarm manager");
    running_ = false;
    
    if (alarmThread_.joinable()) {
        alarmThread_.join();
    }
}

void AlarmManager::alarmLoop() {
    LOG_INFO("Alarm monitoring loop started");
    
    while (running_) {
        std::this_thread::sleep_for(std::chrono::seconds(15));
    }
    
    LOG_INFO("Alarm monitoring loop stopped");
}

}  // namespace service
}  // namespace ems